package org.example.demo1.controller;
import org.example.demo1.Entity.FeedBackRequest;
import org.example.demo1.service.FeedbackCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackCollectionService feedbackService;

    /**
     * 提交解决方案反馈
     */
    @PostMapping("/submit")
    public ResponseEntity<String> submitFeedback(@RequestBody FeedBackRequest request) {
        try {
            String result = feedbackService.processFeedback(
                    request.getFeedbackId(),
                    request.isEffective(),
                    request.getComment()
            );
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.status(500).body("处理反馈失败: " + e.getMessage());
        }
    }

    /**
     * 快速反馈 - 仅标记有效/无效
     */
    @PostMapping("/quick/{feedbackId}")
    public ResponseEntity<String> quickFeedback(
            @PathVariable String feedbackId,
            @RequestParam boolean effective) {
        try {
            String result = feedbackService.processFeedback(feedbackId, effective, "");
            return ResponseEntity.ok(result);
        } catch (Exception e) {
            return ResponseEntity.status(500).body("处理反馈失败: " + e.getMessage());
        }
    }
}
